<?php

namespace app\http\middleware;

use think\Request;
use app\admin\model\AdminAccessLog;
class Log
{
    public function handle(Request $request, \Closure $next)
    {
        $user = session('user');
        if($user) {
            $logData['admin_id'] = $user['admin_id'];
            $logData['username'] = $user['username'];
            $logData['role_name'] = $user['role_name'];
            $logData['method'] = $request->method();
            $logData['params'] = json_encode($request->param(), JSON_UNESCAPED_UNICODE);
            $logData['uri'] = $request->module() . '/' . $request->controller() . '/' . $request->action();
            $model = new AdminAccessLog();
            $id = $model->writeLog($logData);
        }
        return $next($request);
    }
}
